package com.starry.push.netty.vo;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Builder;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author WuChao
 * @version 1.0
 * @date 2020/11/3 15:09
 */
@Data
@Builder
public class WsResponse implements Serializable {

    /**
     * 推送id
     */
    private String id;
    /**
     * 时间，yyyy-MM-dd hh:mm:ss
     */
    private String date;
    /**
     * 推送状态
     * 200-正常
     * 500-异常
     */
    private Integer code;
    /**
     * 状态描述
     */
    private String msg;

    /**
     * 推送类型
     */
    private String pushType;

    /**
     * 推送的数据
     */

    private Object data;



    public static WsResponse error(String msg) {
        return WsResponse.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .date(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()))
                .msg(msg)
                .build();
    }

    public static WsResponse success(String id,String msg,Object data) {
        return WsResponse.builder()
                .code(HttpStatus.OK.value())
                .id(id)
                .date(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()))
                .msg(msg)
                .data(data)
                .build();
    }
}
